<template>
  <div class="jeecg-basic-table jeecg-basic-table-form-container">
    <!--查询区域-->
    <div class="">
      <a-form ref="formRef" @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="4">
            <a-form-item label="年度" name="devNum">
              <a-select
                ref="select"
                v-model:value="queryParam.year"
                :options="yearOptions"
              ></a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="4">
            <a-form-item label="设备编号" name="devName">
              <a-input v-model:value="queryParam.devNumber"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="4">
            <a-form-item label="设备名称:" name="devName">
              <a-input v-model:value="queryParam.devName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="4">
            <a-form-item label="设备状态" name="devName">
              <a-select
                ref="select"
                v-model:value="queryParam.status"
                :options="statusOptions"
                :allowClear="true"
              ></a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
      </template>
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <LabItemsRecordDeviceUsageRateModal ref="registerModal" @success="handleSuccess"></LabItemsRecordDeviceUsageRateModal>
  </div>
</template>

<script lang="ts" name="recordDevice-labItemsRecordDevice" setup>
  import { ref, reactive } from 'vue';
  import { BasicTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns } from './LabItemsRecordDeviceUsageRate.data';
  import { listA, getExportUrl } from './LabItemsRecordDeviceUsageRate.api';
  import LabItemsRecordDeviceUsageRateModal from './components/LabItemsRecordDeviceUsageRateModal.vue';

  const yearOptions = ref<any>([])
  const getYearOptions = () => {
    let startYear:any = 2024;
    for(let i=0;i<10;i++){
      let newYear = startYear+i
      yearOptions.value.push({
        value: `${newYear}`,
        label: `${newYear}`,
      })
    }
  }
  getYearOptions();
  const statusOptions = ref([
    {
      value:'在用',
      label:'在用',
    },
    {
      value:'待报废',
      label:'待报废',
    },
    {
      value:'待维修',
      label:'待维修',
    }
  ])
  const formRef = ref();
  const queryParam = reactive<any>({
   year:(new Date().getFullYear()).toString()
  });

  const registerModal = ref();
  //注册table数据
  const { prefixCls, tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '设备台账管理-设备使用率',
      api: listA,
      columns: columns,
      canResize: false,
      useSearchForm: false,
      showIndexColumn: true,
      actionColumn: {
        width: 120,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        return Object.assign(params, queryParam);
      },
    },
    exportConfig: {
      name: '设备台账管理-设备使用率',
      url: getExportUrl,
      params: queryParam,
    },
  });
  const [registerTable, { reload }, { selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 7 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });

  /**
   * 运行记录
   */
  function handleDetail(record:any) {
    registerModal.value.disableSubmit = true;
    registerModal.value.edit(record);
  }
  /**
   * 成功回调
   */
   function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }
  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: '运行记录',
        onClick: handleDetail.bind(null, record),
      },
    ];
  }
  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }

  /**
   * 重置
   */
  function searchReset() {
    formRef.value.resetFields();
    selectedRowKeys.value = [];
    queryParam.year=(new Date().getFullYear()).toString();
    queryParam.status="";
    //刷新数据
    reload();
  }
</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    .table-page-search-submitButtons {
      display: block;
      margin-bottom: 24px;
      white-space: nowrap;
    }

    .query-group-cust {
      width: calc(50% - 15px);
      min-width: 100px !important;
    }

    .query-group-split-cust {
      width: 30px;
      display: inline-block;
      text-align: center;
    }
  }
</style>
